package com.nursinghome.admin.service.impl;

import com.nursinghome.admin.mapper.HolidaysMapper;
import com.nursinghome.admin.service.HolidayService;
import com.nursinghome.bean.Holidays;
import com.nursinghome.exception.NurisingHomeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HolidayServiceImpl implements HolidayService {
    @Autowired
    private HolidaysMapper holidaysMapper;
    @Override
    public List<Holidays> selectByMname(String mname) {
        return holidaysMapper.selectByMname(mname);
    }

    @Override
    public Boolean updateState(Integer state, Integer hid) throws NurisingHomeException {
        //查看是否存在为审批的hid
        Holidays holidays = holidaysMapper.selectByHidByPaass(hid);
        if (holidays == null){
            throw new NurisingHomeException("没有找到请假单，无法审核");
        }
        return holidaysMapper.updateState(state, hid) == 1;
    }

    @Override
    public List<Holidays> selectAll(String mname) {
        return holidaysMapper.selectAll(mname);
    }

    @Override
    public Holidays selectByHid(Integer hid) {
        return holidaysMapper.selectByHid(hid);
    }
}
